// 模拟 lodash 中的 flowRight

const reverse = (arr) => arr.reverse();
const first = (arr) => arr[0];
const toUpper = (str) => str.toUpperCase();

// const f = compose(toUpper, first, reverse);
// console.log(f(["one", "two", "three"]));

// function compose(...args) {
//   return function (value) {
//     return args.reverse().reduce(function (prev, current) {
//       return current(prev);
//     }, value);
//   };
// }

const compose = (...args) => (value) =>
  args.reduceRight((prev, current) => current(prev), value);

const f = compose(toUpper, first, reverse);
console.log(f(["one", "two", "three"]));
